{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c2b9b673",
   "metadata": {},
   "source": [
    "# 量化分析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "070dc348",
   "metadata": {},
   "source": [
    "## 根据证券代码批量获取股票简要信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e6aaea1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入westat\n",
    "import westat as we"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "230a3497",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>交易所</th>\n",
       "      <th>证券简称</th>\n",
       "      <th>证券代码</th>\n",
       "      <th>现价</th>\n",
       "      <th>涨跌额</th>\n",
       "      <th>涨跌幅</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "      <th>总市值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001</td>\n",
       "      <td>3189.44</td>\n",
       "      <td>38.82</td>\n",
       "      <td>1.23</td>\n",
       "      <td>287604327</td>\n",
       "      <td>35448781</td>\n",
       "      <td>560742.73</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  交易所  证券简称    证券代码       现价   涨跌额  涨跌幅        成交量       成交额       总市值\n",
       "0   1  上证指数  000001  3189.44 38.82 1.23  287604327  35448781 560742.73"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看上证指数\n",
    "we.get_stock()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5f48a55a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>交易所</th>\n",
       "      <th>证券简称</th>\n",
       "      <th>证券代码</th>\n",
       "      <th>现价</th>\n",
       "      <th>涨跌额</th>\n",
       "      <th>涨跌幅</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "      <th>总市值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>招商证券</td>\n",
       "      <td>600999</td>\n",
       "      <td>13.35</td>\n",
       "      <td>0.12</td>\n",
       "      <td>0.91</td>\n",
       "      <td>89163</td>\n",
       "      <td>11903</td>\n",
       "      <td>1160.99</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  交易所  证券简称    证券代码     现价  涨跌额  涨跌幅    成交量    成交额     总市值\n",
       "0   1  招商证券  600999  13.35 0.12 0.91  89163  11903 1160.99"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看指定股票基本数据\n",
    "we.get_stock('600999')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ac082160",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>交易所</th>\n",
       "      <th>证券简称</th>\n",
       "      <th>证券代码</th>\n",
       "      <th>现价</th>\n",
       "      <th>涨跌额</th>\n",
       "      <th>涨跌幅</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "      <th>总市值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>招商证券</td>\n",
       "      <td>600999</td>\n",
       "      <td>13.35</td>\n",
       "      <td>0.12</td>\n",
       "      <td>0.91</td>\n",
       "      <td>89163</td>\n",
       "      <td>11903</td>\n",
       "      <td>1160.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>51</td>\n",
       "      <td>万兴科技</td>\n",
       "      <td>300624</td>\n",
       "      <td>128.00</td>\n",
       "      <td>-2.00</td>\n",
       "      <td>-1.54</td>\n",
       "      <td>94759</td>\n",
       "      <td>121893</td>\n",
       "      <td>176.26</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  交易所  证券简称    证券代码      现价   涨跌额   涨跌幅    成交量     成交额     总市值\n",
       "0   1  招商证券  600999   13.35  0.12  0.91  89163   11903 1160.99\n",
       "1  51  万兴科技  300624  128.00 -2.00 -1.54  94759  121893  176.26"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 批量查看指定股票基本数据\n",
    "we.get_stock(['600999','300624'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c59cc26",
   "metadata": {},
   "source": [
    "## 根据证券代码获取股票分钟数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "85bf6241",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>时间</th>\n",
       "      <th>价格</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>930</td>\n",
       "      <td>3153.31</td>\n",
       "      <td>1799394</td>\n",
       "      <td>1974082916.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>931</td>\n",
       "      <td>3153.17</td>\n",
       "      <td>9044428</td>\n",
       "      <td>10460929060.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>932</td>\n",
       "      <td>3154.28</td>\n",
       "      <td>13304577</td>\n",
       "      <td>16016563157.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>933</td>\n",
       "      <td>3155.72</td>\n",
       "      <td>17095141</td>\n",
       "      <td>20713802079.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>934</td>\n",
       "      <td>3153.63</td>\n",
       "      <td>20515931</td>\n",
       "      <td>25029843233.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>1456</td>\n",
       "      <td>3190.16</td>\n",
       "      <td>281379753</td>\n",
       "      <td>347281468224.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>1457</td>\n",
       "      <td>3189.74</td>\n",
       "      <td>283537273</td>\n",
       "      <td>349790762276.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>1458</td>\n",
       "      <td>3190.27</td>\n",
       "      <td>283686483</td>\n",
       "      <td>349959459183.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>1459</td>\n",
       "      <td>3190.27</td>\n",
       "      <td>283686483</td>\n",
       "      <td>349959459183.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>1500</td>\n",
       "      <td>3189.44</td>\n",
       "      <td>287604327</td>\n",
       "      <td>354487810600.40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>242 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       时间      价格        成交量             成交额\n",
       "0     930 3153.31    1799394   1974082916.90\n",
       "1     931 3153.17    9044428  10460929060.30\n",
       "2     932 3154.28   13304577  16016563157.60\n",
       "3     933 3155.72   17095141  20713802079.60\n",
       "4     934 3153.63   20515931  25029843233.60\n",
       "..    ...     ...        ...             ...\n",
       "237  1456 3190.16  281379753 347281468224.10\n",
       "238  1457 3189.74  283537273 349790762276.80\n",
       "239  1458 3190.27  283686483 349959459183.30\n",
       "240  1459 3190.27  283686483 349959459183.30\n",
       "241  1500 3189.44  287604327 354487810600.40\n",
       "\n",
       "[242 rows x 4 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看上证指数\n",
    "we.get_stock_m()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9ce5123f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>时间</th>\n",
       "      <th>价格</th>\n",
       "      <th>成交量</th>\n",
       "      <th>成交额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>930</td>\n",
       "      <td>13.28</td>\n",
       "      <td>215</td>\n",
       "      <td>285520.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>931</td>\n",
       "      <td>13.33</td>\n",
       "      <td>2747</td>\n",
       "      <td>3659552.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>932</td>\n",
       "      <td>13.32</td>\n",
       "      <td>3665</td>\n",
       "      <td>4882960.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>933</td>\n",
       "      <td>13.33</td>\n",
       "      <td>4898</td>\n",
       "      <td>6526118.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>934</td>\n",
       "      <td>13.33</td>\n",
       "      <td>5944</td>\n",
       "      <td>7918930.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>1456</td>\n",
       "      <td>13.38</td>\n",
       "      <td>85213</td>\n",
       "      <td>113750729.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>1457</td>\n",
       "      <td>13.38</td>\n",
       "      <td>87732</td>\n",
       "      <td>117117437.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>239</th>\n",
       "      <td>1458</td>\n",
       "      <td>13.38</td>\n",
       "      <td>87733</td>\n",
       "      <td>117118775.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>1459</td>\n",
       "      <td>13.38</td>\n",
       "      <td>87733</td>\n",
       "      <td>117118775.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>1500</td>\n",
       "      <td>13.35</td>\n",
       "      <td>89163</td>\n",
       "      <td>119027825.45</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>242 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       时间    价格    成交量          成交额\n",
       "0     930 13.28    215    285520.00\n",
       "1     931 13.33   2747   3659552.00\n",
       "2     932 13.32   3665   4882960.00\n",
       "3     933 13.33   4898   6526118.00\n",
       "4     934 13.33   5944   7918930.00\n",
       "..    ...   ...    ...          ...\n",
       "237  1456 13.38  85213 113750729.44\n",
       "238  1457 13.38  87732 117117437.45\n",
       "239  1458 13.38  87733 117118775.45\n",
       "240  1459 13.38  87733 117118775.45\n",
       "241  1500 13.35  89163 119027825.45\n",
       "\n",
       "[242 rows x 4 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看指定股票分钟数据\n",
    "we.get_stock_m('600999')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f20f7632",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看上证指数\n",
    "we.get_stock_pk('600999')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
